home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / osdepend.h < prev    next >
C/C++ Source or Header  |  2000-05-20  |  13KB  |  349 lines

  1. #ifndef OSDEPEND_H
  2. #define OSDEPEND_H
  3.  
  4. #include "osd_cpu.h"
  5. #include "inptport.h"
  6.  
  7.  
  8. /* The Win32 port requires this constant for variable arg routines. */
  9. #ifndef CLIB_DECL
  10. #define CLIB_DECL
  11. #endif
  12.  
  13. #ifdef __LP64__
  14. #define FPTR long   /* 64bit: sizeof(void *) is sizeof(long)  */
  15. #else
  16. #define FPTR int
  17. #endif
  18.  
  19.  
  20. int osd_init(void);
  21. void osd_exit(void);
  22.  
  23.  
  24. /******************************************************************************
  25.  
  26.   Display
  27.  
  28. ******************************************************************************/
  29.  
  30. struct osd_bitmap
  31. {
  32.     int width,height;       /* width and height of the bitmap */
  33.     int depth;        /* bits per pixel - ASG 980209 */
  34.     void *_private; /* don't touch! - reserved for osdepend use */
  35.     unsigned char **line; /* pointers to the start of each line */
  36. };
  37.  
  38. /* VERY IMPORTANT: the function must allocate also a "safety area" 16 pixels wide all */
  39. /* around the bitmap. This is required because, for performance reasons, some graphic */
  40. /* routines don't clip at boundaries of the bitmap. */
  41. struct osd_bitmap *osd_new_bitmap(int width,int height,int depth);    /* ASG 980209 */
  42. #define osd_create_bitmap(w,h) osd_new_bitmap((w),(h),Machine->scrbitmap->depth)        /* ASG 980209 */
  43. void osd_clearbitmap(struct osd_bitmap *bitmap);
  44. void osd_free_bitmap(struct osd_bitmap *bitmap);
  45. /* Create a display screen, or window, large enough to accomodate a bitmap */
  46. /* of the given dimensions. Attributes are the ones defined in driver.h. */
  47. /* Return a osd_bitmap pointer or 0 in case of error. */
  48. struct osd_bitmap *osd_create_display(int width,int height,int depth,int attributes);
  49. int osd_set_display(int width,int height,int attributes);
  50. void osd_close_display(void);
  51.  
  52. /*
  53. osd_allocate_colors() is called after osd_create_display(), to create and initialize
  54. the palette.
  55. palette is an array of 'totalcolors' R,G,B triplets. The function returns
  56. in *pens the pen values corresponding to the requested colors.
  57. When modifiable is not 0, the palette will be modified later via calls to
  58. osd_modify_pen(). Otherwise, the code can assume that the palette will not change,
  59. and activate special optimizations (e.g. direct copy for a 16-bit display).
  60. The function must also initialize Machine->uifont->colortable[] to get proper
  61. white-on-black and black-on-white text.
  62. Return 0 for success.
  63. */
  64. int osd_allocate_colors(unsigned int totalcolors,const unsigned char *palette,unsigned short *pens,int modifiable);
  65. void osd_modify_pen(int pen,unsigned char red, unsigned char green, unsigned char blue);
  66. void osd_get_pen(int pen,unsigned char *red, unsigned char *green, unsigned char *blue);
  67. void osd_mark_dirty(int xmin, int ymin, int xmax, int ymax, int ui);    /* ASG 971011 */
  68. /*
  69. osd_skip_this_frame() must return 0 if the current frame will be displayed. This
  70. can be used by drivers to skip cpu intensive processing for skipped frames, so the
  71. function must return a consistent result throughout the current frame. The function
  72. MUST NOT check timers and dynamically determine whether to display the frame: such
  73. calculations must be done in osd_update_video_and_audio(), and they must affect the
  74. FOLLOWING frames, not the current one. At the end of osd_update_video_and_audio(),
  75. the code must already now exactly whether the next frame will be skipped or not.
  76. */
  77. int osd_skip_this_frame(void);
  78. void osd_update_video_and_audio(void);
  79. void osd_set_gamma(float _gamma);
  80. float osd_get_gamma(void);
  81. void osd_set_brightness(int brightness);
  82. int osd_get_brightness(void);
  83. void osd_save_snapshot(void);
  84.  
  85.  
  86. /******************************************************************************
  87.  
  88.   Sound
  89.  
  90. ******************************************************************************/
  91.  
  92. /*
  93.   osd_start_audio_stream() is called at the start of the emulation to initialize
  94.   the output stream, the osd_update_audio_stream() is called every frame to
  95.   feed new data. osd_stop_audio_stream() is called when the emulation is stopped.
  96.  
  97.   The sample rate is fixed at Machine->sample_rate. Samples are 16-bit, signed.
  98.  
  99.   When the stream is stereo, left and right samples are alternated in the
  100.   stream.
  101.  
  102.   osd_start_audio_stream() and osd_stop_audio_stream() must return the number of
  103.   samples (or couples of samples, when using stereo) required for next frame.
  104.   This will be around Machine->sample_rate / Machine->drv->frames_per_second,
  105.   the code may adjust it by SMALL AMOUNTS to keep timing accurate and to maintain
  106.   audio and video in sync when using vsync. Note that sound generation,
  107.   especially when DACs are involved, greatly depends on the samples per frame to
  108.   be roughly constant, so the returned value must always stay close to the
  109.   reference value of Machine->sample_rate / Machine->drv->frames_per_second.
  110.   Of course that value is not necessarily an integer so at least a +/- 1
  111.   adjustment is necessary to avoid drifting over time.
  112.  */
  113. int osd_start_audio_stream(int stereo);
  114. int osd_update_audio_stream(INT16 *buffer);
  115. void osd_stop_audio_stream(void);
  116.  
  117. /*
  118.   control master volume, attenuation is the attenuation in dB (a negative
  119.   number).
  120.  */
  121. void osd_set_mastervolume(int attenuation);
  122. int osd_get_mastervolume(void);
  123. void osd_sound_enable(int enable);
  124.  
  125. /* direct access to the Sound Blaster OPL chip */
  126. void osd_opl_control(int chip,int reg);
  127. void osd_opl_write(int chip,int data);
  128.  
  129.  
  130. /******************************************************************************
  131.  
  132.   Keyboard
  133.  
  134. ******************************************************************************/
  135.  
  136. /*
  137.   return a list of all available keys (see input.h)
  138. */
  139. const struct KeyboardInfo *osd_get_key_list(void);
  140.  
  141. /*
  142.   tell whether the specified key is pressed or not. keycode is the OS dependant
  143.   code specified in the list returned by osd_get_key_list().
  144. */
  145. int osd_is_key_pressed(int keycode);
  146.  
  147. /*
  148.   wait for the user to press a key and return its code. This function is not
  149.   required to do anything, it is here so we can avoid bogging down multitasking
  150.   systems while using the debugger. If you don't want to or can't support this
  151.   function you can just return OSD_KEY_NONE.
  152. */
  153. int osd_wait_keypress(void);
  154.  
  155. /*
  156.   Return the Unicode value of the most recently pressed key. This
  157.   function is used only by text-entry routines in the user interface and should
  158.   not be used by drivers. The value returned is in the range of the first 256
  159.   bytes of Unicode, e.g. ISO-8859-1. A return value of 0 indicates no key down.
  160.  
  161.   Set flush to 1 to clear the buffer before entering text. This will avoid
  162.   having prior UI and game keys leak into the text entry.
  163. */
  164. int osd_readkey_unicode(int flush);
  165.  
  166. /* Code returned by the function osd_wait_keypress() if no key available */
  167. #define OSD_KEY_NONE 0xffffffff
  168.  
  169.  
  170. /******************************************************************************
  171.  
  172.   Joystick & Mouse/Trackball
  173.  
  174. ******************************************************************************/
  175.  
  176. /*
  177.   return a list of all available joystick inputs (see input.h)
  178. */
  179. const struct JoystickInfo *osd_get_joy_list(void);
  180.  
  181. /*
  182.   tell whether the specified joystick direction/button is pressed or not.
  183.   joycode is the OS dependant code specified in the list returned by
  184.   osd_get_joy_list().
  185. */
  186. int osd_is_joy_pressed(int joycode);
  187.  
  188.  
  189. /* We support 4 players for each analog control */
  190. #define OSD_MAX_JOY_ANALOG    4
  191. #define X_AXIS          1
  192. #define Y_AXIS          2
  193.  
  194. void osd_poll_joysticks(void);
  195.  
  196. /* Joystick calibration routines BW 19981216 */
  197. /* Do we need to calibrate the joystick at all? */
  198. int osd_joystick_needs_calibration (void);
  199. /* Preprocessing for joystick calibration. Returns 0 on success */
  200. void osd_joystick_start_calibration (void);
  201. /* Prepare the next calibration step. Return a description of this step. */
  202. /* (e.g. "move to upper left") */
  203. char *osd_joystick_calibrate_next (void);
  204. /* Get the actual joystick calibration data for the current position */
  205. void osd_joystick_calibrate (void);
  206. /* Postprocessing (e.g. saving joystick data to config) */
  207. void osd_joystick_end_calibration (void);
  208.  
  209. void osd_trak_read(int player,int *deltax,int *deltay);
  210.  
  211. /* return values in the range -128 .. 128 (yes, 128, not 127) */
  212. void osd_analogjoy_read(int player,int *analog_x, int *analog_y);
  213.  
  214.  
  215. /*
  216.   inptport.c defines some general purpose defaults for key and joystick bindings.
  217.   They may be further adjusted by the OS dependant code to better match the
  218.   available keyboard, e.g. one could map pause to the Pause key instead of P, or
  219.   snapshot to PrtScr instead of F12. Of course the user can further change the
  220.   settings to anything he/she likes.
  221.   This function is called on startup, before reading the configuration from disk.
  222.   Scan the list, and change the keys/joysticks you want.
  223. */
  224. void osd_customize_inputport_defaults(struct ipd *defaults);
  225.  
  226.  
  227. /******************************************************************************
  228.  
  229.   File I/O
  230.  
  231. ******************************************************************************/
  232.  
  233. /* inp header */
  234. typedef struct {
  235.     char name[9];      /* 8 bytes for game->name + NULL */
  236.     char version[3];   /* byte[0] = 0, byte[1] = version byte[2] = beta_version */
  237.     char reserved[20]; /* for future use, possible store game options? */
  238. } INP_HEADER;
  239.  
  240.  
  241. /* file handling routines */
  242. enum
  243. {
  244.     OSD_FILETYPE_ROM = 1,
  245.     OSD_FILETYPE_SAMPLE,
  246.     OSD_FILETYPE_NVRAM,
  247.     OSD_FILETYPE_HIGHSCORE,
  248.     OSD_FILETYPE_HIGHSCORE_DB, /* LBO 040400 */
  249.     OSD_FILETYPE_CONFIG,
  250.     OSD_FILETYPE_INPUTLOG,
  251.     OSD_FILETYPE_STATE,
  252.     OSD_FILETYPE_ARTWORK,
  253.     OSD_FILETYPE_MEMCARD,
  254.     OSD_FILETYPE_SCREENSHOT,
  255.     OSD_FILETYPE_HISTORY,  /* LBO 040400 */
  256.     OSD_FILETYPE_CHEAT,  /* LBO 040400 */
  257.     OSD_FILETYPE_LANGUAGE, /* LBO 042400 */
  258. #ifdef MESS
  259.     OSD_FILETYPE_IMAGE_R,
  260.     OSD_FILETYPE_IMAGE_RW,
  261. #endif
  262.     OSD_FILETYPE_end /* dummy last entry */
  263. };
  264.  
  265. /* gamename holds the driver name, filename is only used for ROMs and    */
  266. /* samples. If 'write' is not 0, the file is opened for write. Otherwise */
  267. /* it is opened for read. */
  268.  
  269. int osd_faccess(const char *filename, int filetype);
  270. void *osd_fopen(const char *gamename,const char *filename,int filetype,int read_or_write);
  271. int osd_fread(void *file,void *buffer,int length);
  272. int osd_fwrite(void *file,const void *buffer,int length);
  273. int osd_fread_swap(void *file,void *buffer,int length);
  274. int osd_fwrite_swap(void *file,const void *buffer,int length);
  275. #if LSB_FIRST
  276. #define osd_fread_msbfirst osd_fread_swap
  277. #define osd_fwrite_msbfirst osd_fwrite_swap
  278. #define osd_fread_lsbfirst osd_fread
  279. #define osd_fwrite_lsbfirst osd_fwrite
  280. #else
  281. #define osd_fread_msbfirst osd_fread
  282. #define osd_fwrite_msbfirst osd_fwrite
  283. #define osd_fread_lsbfirst osd_fread_swap
  284. #define osd_fwrite_lsbfirst osd_fwrite_swap
  285. #endif
  286. int osd_fread_scatter(void *file,void *buffer,int length,int increment);
  287. int osd_fseek(void *file,int offset,int whence);
  288. void osd_fclose(void *file);
  289. int osd_fchecksum(const char *gamename, const char *filename, unsigned int *length, unsigned int *sum);
  290. int osd_fsize(void *file);
  291. unsigned int osd_fcrc(void *file);
  292. /* LBO 040400 - start */
  293. int osd_fgetc(void *file);
  294. int osd_ungetc(int c, void *file);
  295. char *osd_fgets(char *s, int n, void *file);
  296. int osd_feof(void *file);
  297. int osd_ftell(void *file);
  298. /* LBO 040400 - end */
  299.  
  300. /******************************************************************************
  301.  
  302.   Miscellaneous
  303.  
  304. ******************************************************************************/
  305.  
  306. /* called while loading ROMs. It is called a last time with name == 0 to signal */
  307. /* that the ROM loading process is finished. */
  308. /* return non-zero to abort loading */
  309. int osd_display_loading_rom_message(const char *name,int current,int total);
  310.  
  311. /* called when the game is paused/unpaused, so the OS dependant code can do special */
  312. /* things like changing the title bar or darkening the display. */
  313. /* Note that the OS dependant code must NOT stop processing input, since the user */
  314. /* interface is still active while the game is paused. */
  315. void osd_pause(int paused);
  316.  
  317. /* control keyboard leds or other indicators */
  318. void osd_led_w(int led,int on);
  319.  
  320.  
  321.  
  322. #ifdef MAME_NET
  323. /* network */
  324. int osd_net_init(void);
  325. int osd_net_send(int player, unsigned char buf[], int *size);
  326. int osd_net_recv(int player, unsigned char buf[], int *size);
  327. int osd_net_sync(void);
  328. int osd_net_input_sync(void);
  329. int osd_net_exit(void);
  330. int osd_net_add_player(void);
  331. int osd_net_remove_player(int player);
  332. int osd_net_game_init(void);
  333. int osd_net_game_exit(void);
  334. #endif /* MAME_NET */
  335.  
  336. #ifdef MESS
  337. int osd_num_devices(void);
  338. const char *osd_get_device_name(int i);
  339. void osd_change_device(const char *vol);
  340. void *osd_dir_open(const char *mdirname, const char *filemask);
  341. int osd_dir_get_entry(void *dir, char *name, int namelength, int *is_dir);
  342. void osd_dir_close(void *dir);
  343. #endif
  344.  
  345.  
  346. void CLIB_DECL logerror(const char *text,...);
  347.  
  348. #endif
  349.